﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using YiSha.Admin.Web.Controllers;
using YiSha.Basics;
using YiSha.Entity.SystemManage;
using YiSha.Model.Param.SystemManage;
using YiSha.Model.Result;
using YiSha.Service.SystemManage;
using YiSha.Util.Model;

namespace YiSha.Admin.Web.Areas.SystemManage.Controllers
{
    [Area("SystemManage")]
    public class AreaController : BaseController
    {
        public AreaService AreaService { get; set; }

        #region 视图功能
        [AuthorizeFilter("system:area:view")]
        public IActionResult AreaIndex()
        {
            return View();
        }

        public IActionResult AreaForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        [AuthorizeFilter("system:area:search")]
        public async Task<IActionResult> GetListJson(AreaListParam param)
        {
            TData<List<AreaEntity>> obj = await AreaService.GetList(param);
            return Json(obj);
        }

        [AuthorizeFilter("system:area:search")]
        public async Task<IActionResult> GetPageListJson(AreaListParam param, Pagination pagination)
        {
            TData<List<AreaEntity>> obj = await AreaService.GetPageList(param, pagination);
            return Json(obj);
        }

        public async Task<IActionResult> GetZtreeAreaListJson(AreaListParam param)
        {
            TData<List<ZtreeInfo>> obj = await AreaService.GetZtreeAreaList(param);
            return Json(obj);
        }

        public async Task<IActionResult> GetFormJson(string id)
        {
            TData<AreaEntity> obj = await AreaService.GetEntity(id);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("system:area:add,ystem:area:edit")]
        public async Task<IActionResult> SaveFormJson(AreaEntity entity)
        {
            TData<string> obj = await AreaService.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("system:area:delete")]
        public async Task<IActionResult> DeleteFormJson(List<string> ids)
        {
            TData obj = await AreaService.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}
